
import os
import sys
from os.path import dirname, abspath, join
import subprocess


# Find code directory relative to our directory
THIS_DIR = dirname(__file__)
CODE_DIR = abspath(join(THIS_DIR, '..', 'code'))
sys.path.append(CODE_DIR)



# implement pip as a subprocess:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 
'econ-ark'],shell=True)
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 
'numpy'],shell=True)
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 
'matplotlib '],shell=True)
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 
'scipy'],shell=True)
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 
'ipywidgets'],shell=True)

import pandas as pd
import numpy as np

os.chdir('C:/code/output')
def cost_dollar(n, intrate, minrate,minrate2,payment,payment2,spending, spending2):
    x=[]
    y=[]
    z=[]
    w=[]
    debt=5000
    debt2=5000
    for i in range(n):
        interest=np.where(payment>=minrate*debt, (debt-payment)*intrate, (debt-payment)*intrate*10/30 +(debt*minrate-payment)*(intrate+0.01)*20/30 + (debt-debt*minrate)*intrate*20/30)
        interest2=np.where(payment2>=minrate2*debt2, (debt2-payment2)*intrate, (debt2-payment2)*intrate*10/30 +(debt2*minrate2-payment2)*(intrate+0.01)*20/30 + (debt2-debt2*minrate2)*intrate*20/30)
        new_debt=interest+spending-payment
        new_debt2=interest2+spending2-payment2
        cost=interest
        cost2=interest2
        debt=debt+new_debt
        debt2=debt2+new_debt2
        x.append(cost)
        y.append(cost2)
        z.append(debt)
        w.append(debt2)
        
        df = pd.DataFrame(list(zip(x, y,z,w)),
               columns =['Cost of borrowing, 20% Min Payment', 'Cost of borrowing, 40% Min Payment',
                         'Debt, 20% Min Payment','Debt, 40% Min Payment'] )
        
        
        
    
    return df


df=cost_dollar(n=100, intrate=0.02, minrate=0.2,minrate2=0.4,payment=0.50*5000,payment2=0.50*5000,spending=0.50*5000, spending2=0.50*5000)


# Python program to show pyplot module
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
fig = plt.figure(figsize = (5, 4))
 
# plotting 1st dataset to the figure
plt.plot(df['Debt, 20% Min Payment'], df['Cost of borrowing, 20% Min Payment'], c='k' ,linewidth=2,label = '20% Min Payment')
 
# plotting 2nd dataset to the figure
plt.plot(df['Debt, 40% Min Payment'], df['Cost of borrowing, 40% Min Payment'], c='k' , linestyle='--',
     linewidth=2, label = '40% Min Payment')
plt.xlabel("Debt")
plt.ylabel("Cost of Borrowing (TL)")
plt.legend(title='Cost of Borrowing with:')
plt.title('Cost of Borrowing Before and After policy (TL)')
plt.savefig("FigureA4PanelA.jpg")
             
def cost(n, intrate, minrate,minrate2,payment,payment2):
    x=[]
    y=[]
    z=[]
    w=[]
    debt=5000
    debt2=5000
    spending = payment
    spending2 = payment2
    for i in range(n):
        interest=np.where(payment>=minrate*debt, (debt-payment)*intrate, (debt-payment)*intrate*10/30 +(debt*minrate-payment)*(intrate+0.06)*20/30 + (debt-debt*minrate)*intrate*20/30)
        interest2=np.where(payment2>=minrate2*debt2, (debt2-payment2)*intrate, (debt2-payment2)*intrate*10/30 +(debt2*minrate2-payment2)*(intrate+0.06)*20/30 + (debt2-debt2*minrate2)*intrate*20/30)
        new_debt=interest+spending-payment
        new_debt2=interest2+spending2-payment2
        cost=interest/(debt-payment)*100
        cost2=interest2/(debt2-payment2)*100
        debt=debt+new_debt
        spending = payment + interest
        spending2 = payment2 + interest2
        debt2=debt2+new_debt2
        x.append(cost)
        y.append(cost2)
        z.append(debt)
        w.append(debt2)
        
        df = pd.DataFrame(list(zip(x, y,z,w)),
               columns =['Cost of borrowing, 20% Min Payment', 'Cost of borrowing, 40% Min Payment',
                         'Debt, 20% Min Payment','Debt, 40% Min Payment'] )
        
        
        
    
    return df
    
df=cost(n=50, intrate=0.02, minrate=0.2,minrate2=0.4,payment=0.50*5000,payment2=0.50*5000)
from matplotlib import pyplot as plt
fig = plt.figure(figsize = (5, 4))
plt.plot(df['Debt, 20% Min Payment'], df['Cost of borrowing, 20% Min Payment'], c='k' ,
     linewidth=2,label = '20% Min Payment')
plt.xlabel("Debt")
plt.ylabel("Cost of Borrowing")
plt.plot(df['Debt, 40% Min Payment'], df['Cost of borrowing, 40% Min Payment'], c='k' , linestyle='--',
     linewidth=2, label = '40% Min Payment')
plt.legend(title='Cost of Borrowing with:')
plt.title('Cost of Borrowing Before and After policy')
plt.savefig("FigureA4PanelB.png")


import numpy as np
mystr = lambda number : "{:.4f}".format(number)

from copy import copy

from scipy.interpolate import interp1d
from scipy.optimize import root_scalar

from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

import matplotlib.pyplot as plt
from copy import deepcopy
from ConsIndShock import KinkedRconsumerType,c
from HARK.distribution import DiscreteDistribution
from HARK.ConsumptionSaving.ConsIndShockModel import IndShockConsumerType
from HARK.ConsumptionSaving.ConsIndShockModel import init_idiosyncratic_shocks,init_kinked_R,ConsKinkedRsolver


KinkedDict ={  # Click the arrow to expand this parameter dictionary
    # Parameters shared with the perfect foresight model #
    "CRRA": 1.8,  # Coefficient of relative risk aversion
    "mrate":0.0,
    "DiscFac":  0.95,  # Intertemporal discount factor
    "LivPrb": 74*[1.00], #[0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7],
    "PermGroFac":  [1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.025, 1.03, 1.035, 1.04, 1.045, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.025, 1.01, 1.01, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
    "BoroCnstArt": None,  # Artificial borrowing constraint; imposed minimum level of end-of period assets
    # New parameters unique to the "kinked R" model
    "Rboro": 1.06,  # Interest factor on borrowing (a < 0)
    "Rsave": 1.03,  # Interest factor on saving (a > 0)
    # Parameters th9at specify the income distribution over the lifecycle (shared with IndShockConsumerType)
    "PermShkStd": [0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
,
    "PermShkCount": 7,  # Number of points in discrete approximation to permanent income shocks
    "TranShkStd": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
,
    "TranShkCount": 7,  # Number of points in discrete approximation to transitory income shocks
    "UnempPrb": 0.10,  # Probability of unemployment while working
    "IncUnemp": 0.75,  # Unemployment benefits replacement rate
    "UnempPrbRet": 0.0005,  # Probability of "unemployment" while retired
    "IncUnempRet": 0.0,  # "Unemployment" benefits when retired
    "T_retire": 40,  # Period of retirement (0 --> no retirement)
    "tax_rate": 0.0,  # Flat income tax rate (legacy parameter, will be removed in future)
    # Parameters for constructing the "assets above minimum" grid (shared with IndShockConsumerType)
    "aXtraMin": 0.001,  # Minimum end-of-period "assets above minimum" value
    "aXtraMax": 20,  # Maximum end-of-period "assets above minimum" value
    "aXtraCount": 48,  # Number of points in the base grid of "assets above minimum"
    "aXtraNestFac": 3,  # Exponential nesting factor when constructing "assets above minimum" grid
    "aXtraExtra": [None],  # Additional values to add to aXtraGrid
    # A few other paramaters (shared with IndShockConsumerType)
    "vFuncBool": True,  # Whether to calculate the value function during solution
    "CubicBool": True,  # Preference shocks currently only compatible with linear cFunc
    "T_cycle": 74,  # Number of periods in the cycle for this agent type
    # Parameters only used in simulation (shared with PerfForesightConsumerType)
    "AgentCount": 10000,  # Number of agents of this type
    "T_sim": 75,  # Number of periods to simulate
    "aNrmInitMean": -6.0,  # Mean of log initial assets
    "aNrmInitStd": 0.0,  # Standard deviation of log initial assets
    "pLvlInitMean": 0.0,  # Mean of log initial permanent income
    "pLvlInitStd": 0.0,  # Standard deviation of log initial permanent income
    "PermGroFacAgg": 0.0,  # Aggregate permanent income growth factor
    "T_age": 75,  # Age after which simulated agents are automatically killed
}

IdiosyncDict = {  # Click the arrow to expand this parameter dictionary
    # Parameters shared with the perfect foresight model #
    "CRRA": 1.8,  # Coefficient of relative risk aversion
    "DiscFac":  0.95,  # Intertemporal discount factor
    "LivPrb": 74*[1.00], #[0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.99,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7],
    "PermGroFac": [1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.02, 1.025, 1.03, 1.035, 1.04, 1.045, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.025, 1.01, 1.01, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
    "BoroCnstArt": 0.0,  # Artificial borrowing constraint; imposed minimum level of end-of period assets
    # New parameters unique to the "kinked R" model
    "Rfree": 1.03,  # Interest factor on saving (a > 0)
    # Parameters th9at specify the income distribution over the lifecycle (shared with IndShockConsumerType)
    "PermShkStd": [0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
,
    "PermShkCount": 7,  # Number of points in discrete approximation to permanent income shocks
    "TranShkStd": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
,
    "TranShkCount": 7,  # Number of points in discrete approximation to transitory income shocks
    "UnempPrb": 0.10,  # Probability of unemployment while working
    "IncUnemp": 0.75,  # Unemployment benefits replacement rate
    "UnempPrbRet": 0.0005,  # Probability of "unemployment" while retired
    "IncUnempRet": 0.0,  # "Unemployment" benefits when retired
    "T_retire": 40,  # Period of retirement (0 --> no retirement)
    "tax_rate": 0.0,  # Flat income tax rate (legacy parameter, will be removed in future)
    # Parameters for constructing the "assets above minimum" grid (shared with IndShockConsumerType)
    "aXtraMin": 0.001,  # Minimum end-of-period "assets above minimum" value
    "aXtraMax": 20,  # Maximum end-of-period "assets above minimum" value
    "aXtraCount": 48,  # Number of points in the base grid of "assets above minimum"
    "aXtraNestFac": 3,  # Exponential nesting factor when constructing "assets above minimum" grid
    "aXtraExtra": [None],  # Additional values to add to aXtraGrid
    # A few other paramaters (shared with IndShockConsumerType)
    "vFuncBool": True,  # Whether to calculate the value function during solution
    "CubicBool": True,  # Preference shocks currently only compatible with linear cFunc
    "T_cycle": 74,  # Number of periods in the cycle for this agent type
    # Parameters only used in simulation (shared with PerfForesightConsumerType)
    "AgentCount": 10000,  # Number of agents of this type
    "T_sim": 75,  # Number of periods to simulate
    "aNrmInitMean": -6.0,  # Mean of log initial assets
    "aNrmInitStd": 0.0,  # Standard deviation of log initial assets
    "pLvlInitMean": 0.0,  # Mean of log initial permanent income
    "pLvlInitStd": 0.0,  # Standard deviation of log initial permanent income
    "PermGroFacAgg": 0.0,  # Aggregate permanent income growth factor
    "T_age": 75,  # Age after which simulated agents are automatically killed
}



hardConstrained = IndShockConsumerType(**IdiosyncDict)
hardConstrained.cycles =2 
hardConstrained.solve()

KinkedConsumer=KinkedRconsumerType(**KinkedDict)
KinkedConsumer.cycles= 2 
KinkedConsumer.solve()

import pandas as pd
do_simulation=True 
KinkedConsumer.unpack('cFunc')  


if do_simulation:
  KinkedConsumer.T_sim = 74 
  KinkedConsumer.track_vars = ['aNrm','mNrm','cNrm','pLvl','t_age','bNrm'] 
  KinkedConsumer.initialize_sim()
  KinkedConsumer.simulate()

KinkedConsumer5=deepcopy(KinkedConsumer)
if do_simulation:
  KinkedConsumer5.T_sim = 74 #Simulate agents for 49 periods since their lifespan is 49 periods
  KinkedConsumer5.track_vars = ['aNrm','mNrm','cNrm','pLvl','t_age','bNrm'] #track these variables
  KinkedConsumer5.initialize_sim()
  KinkedConsumer5.simulate(20)
  KinkedConsumer5.mrate=0.20
  KinkedConsumer5.Rboro=c(KinkedConsumer5)
  KinkedConsumer5.solve()
  KinkedConsumer5.unpack('cFunc')
  KinkedConsumer5.simulate(54)


KinkedConsumer6=deepcopy(KinkedConsumer)
if do_simulation:
  KinkedConsumer6.T_sim = 74 
  KinkedConsumer6.track_vars = ['aNrm','mNrm','cNrm','pLvl','t_age','bNrm'] #track these variables
  KinkedConsumer6.initialize_sim()
  KinkedConsumer6.simulate(20)
  KinkedConsumer6.mrate=0.2
  KinkedConsumer6.Rboro=c(KinkedConsumer6)        
  KinkedConsumer6.solve()
  KinkedConsumer6.unpack('cFunc')
  KinkedConsumer6.simulate(1)
  KinkedConsumer6.mrate=0.3
  KinkedConsumer6.Rboro=c(KinkedConsumer6)   
  KinkedConsumer6.solve()
  KinkedConsumer6.unpack('cFunc')
  KinkedConsumer6.simulate(1)
  KinkedConsumer6.mrate=0.35
  KinkedConsumer6.Rboro=c(KinkedConsumer6)  
  KinkedConsumer6.solve()
  KinkedConsumer6.unpack('cFunc')
  KinkedConsumer6.simulate(1)
  KinkedConsumer6.mrate=0.4
  KinkedConsumer6.Rboro=c(KinkedConsumer6)          
  KinkedConsumer6.solve()
  KinkedConsumer6.unpack('cFunc')
  KinkedConsumer6.simulate(51)

hardConstrained.unpack('cFunc')  

if do_simulation:
  hardConstrained.T_sim = 74 
  hardConstrained.track_vars = ['aNrm','mNrm','cNrm','pLvl','t_age','bNrm'] 
  hardConstrained.initialize_sim()
  hardConstrained.simulate()

raw = {'T_age': KinkedConsumer.history['t_age'].flatten()+25,
            'cNrmNow_KinkedConsumer': KinkedConsumer.history['cNrm'].flatten(),
            'cNrmNow_KinkedConsumer5': KinkedConsumer5.history['cNrm'].flatten(),
            'cNrmNow_KinkedConsumer6': KinkedConsumer6.history['cNrm'].flatten(),
            'cNrmNow_hardConstrained': hardConstrained.history['cNrm'].flatten(),
            'mNrmNow_KinkedConsumer':  KinkedConsumer.history['aNrm'].flatten(),
            'mNrmNow_KinkedConsumer5': KinkedConsumer5.history['aNrm'].flatten(),
            'mNrmNow_KinkedConsumer6': KinkedConsumer6.history['aNrm'].flatten(),
            'mNrmNow_hardConstrained': hardConstrained.history['aNrm'].flatten(),
            }

Data = pd.DataFrame(raw)  
Data['Cons_KinkedConsumer'] = Data.cNrmNow_KinkedConsumer 
Data['Cons_KinkedConsumer5'] = Data.cNrmNow_KinkedConsumer5 
Data['Cons_KinkedConsumer6'] = Data.cNrmNow_KinkedConsumer6 
Data['Cons_hardConstrained'] = Data.cNrmNow_hardConstrained 
Data['Debt_KinkedConsumer5_anrm'] = -Data.mNrmNow_KinkedConsumer5 
Data['Debt_KinkedConsumer6_anrm'] = -Data.mNrmNow_KinkedConsumer6 
Data['Debt_KinkedConsumer_anrm'] = -Data.mNrmNow_KinkedConsumer


from scipy import stats

os.chdir('C:/code/output')

plt.figure(figsize = (12,8))
AgeMeans = Data.groupby(['T_age']).mean().reset_index() # Group the dataset by T_age and get the mean.
plt.plot(AgeMeans.T_age[:40], AgeMeans.Cons_hardConstrained[:40], 'k-', linewidth=3, label='Consumption:Hard Borrowing Constraint')
plt.plot(AgeMeans.T_age[:40], AgeMeans.Cons_KinkedConsumer[:40], 'k--', linewidth=3,label='Consumption:Soft Borrowing Constraint Before Policy-baseline')
plt.legend(fontsize=15)
plt.xlabel('AGE', fontsize=17)
plt.ylabel('CONSUMPTION', fontsize=17)
plt.title('CONSUMPTION', fontsize=25)
plt.tick_params(axis='both', which='major', labelsize=20)
plt.ylim(0.75,1.25)
plt.savefig('FigureA5.png')
plt.show
plt.figure()
plt.figure(figsize = (12,8))
AgeMeans.Debt_KinkedConsumer_anrm[AgeMeans.Debt_KinkedConsumer_anrm < 0] = 0
AgeMeans.Debt_KinkedConsumer6_anrm[AgeMeans.Debt_KinkedConsumer6_anrm < 0] = 0
AgeMeans.Debt_KinkedConsumer5_anrm[AgeMeans.Debt_KinkedConsumer5_anrm < 0] = 0
plt.plot(AgeMeans.T_age[:40], AgeMeans.Debt_KinkedConsumer_anrm[:40], 'k-', linewidth=3,label='Debt/Savings:Soft Borr. Constraint Before Policy-baseline')
plt.plot(AgeMeans.T_age[:40], AgeMeans.Debt_KinkedConsumer5_anrm[:40],'k:', linewidth=3,label='Debt/Savings:Soft Borr. Constraint After Policy-policy announced at age 45, implemented at 45.5')
plt.plot(AgeMeans.T_age[:40], AgeMeans.Debt_KinkedConsumer6_anrm[:40], 'k--', linewidth=3,label='Debt/Savings:Soft Borr. Constraint After Policy-policy announced at age 45, implemented at 45.5, 46, 46.5, 47')
ax = plt.subplot(1, 1, 1)
plt.legend(fontsize=11)
plt.xlabel('AGE', fontsize=17)
plt.ylabel('DEBT', fontsize=17)
plt.title('DEBT', fontsize=25)
plt.tick_params(axis='both', which='major', labelsize=20)
plt.ylim(-1.25,1.25)
plt.savefig('FigureA7.png')
plt.show
plt.figure()
plt.figure(figsize = (12,8))
plt.plot(AgeMeans.T_age[:40], AgeMeans.Cons_KinkedConsumer[:40], 'k-', linewidth=3,label='Consumption:Soft Borrowing Constraint Before Policy-baseline')
plt.plot(AgeMeans.T_age[:40], AgeMeans.Cons_KinkedConsumer5[:40],'k:', linewidth=3,label='Consumption:Soft Borrowing Constraint After Policy-policy announced at age 45, implemented at 45.5')
plt.plot(AgeMeans.T_age[:40], AgeMeans.Cons_KinkedConsumer6[:40],'k--', linewidth=3,label='Consumption:Soft Borrowing Constraint After Policy-policy announced at age 45, implemented at 45.5, 46, 46.5, 47')
plt.legend(fontsize=10)
plt.xlabel('AGE', fontsize=17)
plt.ylabel('CONSUMPTION', fontsize=17)
plt.title('CONSUMPTION', fontsize=25)
plt.tick_params(axis='both', which='major', labelsize=20)
plt.ylim(0.75,1.25)
plt.savefig('FigureA6.png')
plt.show
plt.figure()

if __name__ == "__main__":
    print('Task Done')